package com.win.cn.core.pane;

import com.win.cn.WinStart;
import com.win.cn.control.SoftWareControl;
import com.win.cn.core.model.ColorControl;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

/**
 * 左侧活动栏
 * 
 * @author wangzh
 * 2018年6月6日 上午11:10:40
 */
public class ActivityPane {
	
	public AnchorPane createActivityPane(){
		AnchorPane leftPane=new AnchorPane();
		leftPane.setMaxWidth(50.0);
		leftPane.setMinWidth(50.0);
		leftPane.getChildren().add(createVbox());
		leftPane.setPadding(new Insets(10, 0, 0, 0));
		
		//添加背景色
		leftPane.setStyle("-fx-background-color:"+ColorControl.activityBackgroundColor);
    	
		return leftPane;
	}
	
	/**
	 * 主菜单
	 */
	public VBox createVbox(){
		VBox vbox=new VBox();
		Button tool=new Button();;  
		Button start=new Button();
		tool.setBackground(new Background(new BackgroundFill(Color.rgb(37,174,96, .99),null,null)));	     
		tool.setStyle("-fx-background-image:url('./img/settings.png');-fx-background-size: 45px;-fx-background-repeat:no-repeat;-fx-background-color:"+ColorControl.activitySelectColor);
		tool.setPrefWidth(50);
		tool.setPrefHeight(50);
		tool.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
            	clearResourcesPane();
            	tool.setStyle("-fx-background-image:url('./img/settings.png');-fx-background-size: 45px;-fx-background-repeat:no-repeat;-fx-background-color:"+ColorControl.activitySelectColor);
            	start.setStyle("-fx-background-image:url('./img/display.png');-fx-background-size: 45px;-fx-background-repeat:no-repeat;-fx-background-color:"+ColorControl.activityBackgroundColor);
            	
                WinStart.resourcesPane.getChildren().add(new ResourcesPane().getToolTree());
                WinStart.borderPane.setCenter(new DetailPane().createTimePane());
            }
        });
		
		
		
		start.setStyle("-fx-background-image:url('./img/display.png');-fx-background-size: 45px;-fx-background-repeat:no-repeat;-fx-background-color:"+ColorControl.activityBackgroundColor);
		start.setPrefWidth(50);
		start.setPrefHeight(50);
		
		start.setPrefWidth(50.0);
		start.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
            	clearResourcesPane();
            	tool.setStyle("-fx-background-image:url('./img/settings.png');-fx-background-size: 45px;-fx-background-repeat:no-repeat;-fx-background-color:"+ColorControl.activityBackgroundColor);
            	start.setStyle("-fx-background-image:url('./img/display.png');-fx-background-size: 45px;-fx-background-repeat:no-repeat;-fx-background-color:"+ColorControl.activitySelectColor);
            	WinStart.resourcesPane.getChildren().add(new ResourcesPane().getStartTree());
            	WinStart.borderPane.setCenter(new SoftWareControl().createTableView());
            }
        });
		
		vbox.getChildren().addAll(tool,start);
		return vbox;
	}
	
	/**
	 * 清空资源窗格组件
	 */
	public void clearResourcesPane(){
		//清空软件
    	int size=WinStart.resourcesPane.getChildren().size();
    	if(size>0){
    		for(int i=0;i<size;i++){
    			WinStart.resourcesPane.getChildren().remove(i);
    		}
    	}
    	WinStart.borderPane.setCenter(null);
	}
	

}
